<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>管理人员修改信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon"
          href="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/basic/favicon.ico">
    <link rel="stylesheet" th:href="@{/css/mouse.css}">
    <link rel="stylesheet" th:href="@{/js/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">管理账号</label>
                <div class="layui-input-block">
                    <input type="text" value="" class="layui-input" id="username" style="border-color: white" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="email" name="email" lay-verify="email" placeholder="请输入邮箱" value="" class="layui-input"
                           id="email">
                    <tip>填写自己管理账号对应的邮箱！</tip>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="remarks" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" th:src="@{/js/jquery-3.5.1.js}"></script>
<script>
    $(document).on('input', '#email', function () {
        let email = $("#email").val();
        $.ajax({
            url: "/api/emailjudge",
            type: "GET",
            data: {email: email},
            success: function (data) {
                if (!data) {
                    layer.alert("此邮箱已在数据库！", {title: "重点提示"});
                    $("#email").val("");
                }
            }
        });
    });
</script>
<script th:src="@{/js/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.jquery;

        $("#username").val(layui.data('user').usermessage.username);
        $("#email").val(layui.data('user').usermessage.email);

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终提交的数据'
            }, function () {
                $.ajax({
                    url: '/twei/updatemessage',
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify({
                        "nowusername": layui.data('user').usermessage.username
                        , "userdata": data.field
                    }),
                    success: function (result) {
                        if (result.code === 200) {
                            layui.data('user', {
                                key: 'usermessage'
                                , value: result.data
                            });
                            layer.msg(result.data.message, {icon: 1, time: 800}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result.data, {icon: 2, time: 800}, function () {
                                location.reload();
                            });
                        }
                    }
                });
            });
            return false;
        });
    });
</script>
</body>
</html>